package com.tentact.servlets;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.tentact.service.Chf_mRoomService;
import com.tentact.vo.MeetingRoom;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

@WebServlet(name = "Chf_sMeRoomServlet", value = "/Chf_sMeRoomServlet")
public class Chf_sMeRoomServlet extends HttpServlet {
    Chf_mRoomService c_ms=new Chf_mRoomService();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        List<MeetingRoom> mR_list=new ArrayList<>();
        if (request.getParameter("capacity")!=null){
            int capacity =Integer.parseInt(request.getParameter("capacity"));
            System.out.println(capacity);
            mR_list=c_ms.selectMeetingByCapacity(capacity);
            ObjectMapper om=new ObjectMapper();
            String mR_String = om.writeValueAsString(mR_list);
            response.setContentType("application/json;charset=utf-8");
            PrintWriter pw=response.getWriter();
            pw.print(mR_String);
            pw.flush();
            pw.close();
        }

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            doGet(request,response);
    }
}
